package cn.tedu.store.product.webapi.controller;

import cn.tedu.store.commons.pojo.product.dto.HomeAdvertiseAddNewDTO;
import cn.tedu.store.commons.pojo.product.dto.HomeAdvertiseUpdateDTO;
import cn.tedu.store.commons.pojo.product.vo.HomeAdvertiseListItemVO;
import cn.tedu.store.commons.pojo.product.vo.HomeAdvertiseStandardVO;
import cn.tedu.store.product.service.IHomeAdvertiseService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图控制器
 *
 * @author RelentlessFlow
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "11.轮播图管理模块")
@RestController
@RequestMapping("/advertises")
public class HomeAdvertiseController {

    @Autowired
    private IHomeAdvertiseService homeAdvertiseService;

    @ApiOperation("添加轮播图")
    @ApiOperationSupport(order = 100)
    @PostMapping("add-new")
    public JsonResult<Void> addNew(HomeAdvertiseAddNewDTO homeAdvertiseAddNewDTO){
        log.debug("开始处理[添加轮播图]请求 参数:{}",homeAdvertiseAddNewDTO);
        homeAdvertiseService.addNew(homeAdvertiseAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除轮播图")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "轮播图id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理[删除轮播博图]的请求 参数:{}", id);
        homeAdvertiseService.delete(id);
        log.debug("删除轮播图成功!");
        return JsonResult.ok();
    }

    @ApiOperation("启用轮播图")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "轮播图id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/enable")
    public JsonResult<Void> setUp(@PathVariable Long id) {
        log.debug("准备处理[启用轮播图]请求 参数:{}", id);
        homeAdvertiseService.setUp(id);
        return JsonResult.ok();
    }

    @ApiOperation("禁用轮播图")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "轮播图id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/disable")
    public JsonResult<Void> setDown(@PathVariable Long id) {
        log.debug("准备处理[禁用轮播图]请求 参数:{}", id);
        homeAdvertiseService.setDown(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改轮播图")
    @ApiOperationSupport(order = 320)
    @ApiImplicitParam(name = "id", value = "轮播图id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id , HomeAdvertiseUpdateDTO homeAdvertiseUpdateDTO) {
        log.debug("处理[修改轮播图]请求 参数:{},{}", id, homeAdvertiseUpdateDTO);
        homeAdvertiseService.updateById(id, homeAdvertiseUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("获取轮播图详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "轮播图id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}/get-by-id")
    public JsonResult<HomeAdvertiseStandardVO> getStandardById(@PathVariable Long id){
        log.debug("开始处理[获取轮播图详情]请求 参数:{}",id);
        return JsonResult.ok(homeAdvertiseService.getStandardById(id));
    }

    @ApiOperation("获取轮播图列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("")
    public JsonResult<List<HomeAdvertiseListItemVO>> list(){
        log.debug("开始处理[获取轮播图列表]请求 参数:无");
        return JsonResult.ok(homeAdvertiseService.list());
    }

}
